class RemindersController < ApplicationController
  before_filter :find_contact
  before_filter :find_reminder, :except => [:new, :create]

  def index
  end

  def show
  end

  def new
    @reminder = Reminder.new
  end

  def create
    @reminder = Reminder.new(params[:reminder])
    
    if @contact.reminders << @reminder
      redirect_to_contact('Reminder successfully created.')
    else
      render :action => "new"
    end
  end

  def edit
  end

  def update
    if @reminder.update_attributes(params[:reminder])
      redirect_to_contact('Reminder successfully created.')
    else
      render :action => "edit"
    end
  end

  def destroy
    @reminder.destroy
     redirect_to_contact('Reminder successfully destroyed.')
  end
  
  private 
  
  def redirect_to_contact(notice)
    flash[:notice] = notice
    redirect_to :controller => "contacts",
                :action => "show",
                :id => @contact.id
  end
 
  def find_contact
    @contact = Contact.find(params[:contact_id])
  end
  
  def find_reminder
    @reminder = @contact.reminders.find(params[:id])
  end
  
end
